﻿using MongoDB.Bson.Serialization.Attributes;
using MongoDB.Bson;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gds.Model.ConfigModel.Controller
{
    public class ControllerConfigModel : INotifyPropertyChanged
    {
        #region privata param
        private string _controllerId;
        private string _controllerType;
        private string _totalLineNumber;
        private string _controllerFactory;
        private int _controllerAddress;
        private int _controllerChannalNumber;
        private int _relayIndex;
        private int _relaySwitchIndex;
        private int _refreashTime;
        #endregion
        /// <summary>
        /// 用于减少保存次数
        /// </summary>
        public int RefreashTime
        {
            get { return _refreashTime; }
            set
            {
                _refreashTime = value;
                OnPropertyChanged("RefreashTime");
            }
        }
        [BsonId]
        public ObjectId _Id { get; set; }
        /// <summary>
        /// 控制器序号
        /// </summary>
        public string ControllerId
        {
            get { return _controllerId; }
            set
            {
                _controllerId = value;
                OnPropertyChanged("ControllerId");
            }
        }
        /// <summary>
        /// 控制器类型
        /// </summary>
        public string ControllerType
        {
            get { return _controllerType; }
            set
            {
                _controllerType = value;
                OnPropertyChanged("ControllerType");
            }
        }
        /// <summary>
        /// 对应总线号
        /// </summary>
        public string TotalLineNumber
        {
            get { return _totalLineNumber; }
            set
            {
                _totalLineNumber = value;
                OnPropertyChanged("TotalLineNumber");
            }
        }
        /// <summary>
        /// 控制器厂家 用于加载不同的协议
        /// </summary>
        public string ControllerFactory
        {
            get { return _controllerFactory; }
            set
            {
                _controllerFactory = value;
                OnPropertyChanged("ControllerFactory");
            }
        }
        /// <summary>
        /// 控制器地址
        /// </summary>
        public int ControllerAddress
        {
            get { return _controllerAddress; }
            set
            {
                _controllerAddress = value;
                OnPropertyChanged("ControllerAddress");
            }
        }
        /// <summary>
        /// 控制器通道数
        /// </summary>
        public int ControllerChannalNumber
        {
            get { return _controllerChannalNumber; }
            set
            {
                _controllerChannalNumber = value;
                OnPropertyChanged("ControllerChannalNumber");
            }
        }
        /// <summary>
        /// 关联继电器Id
        /// </summary>
        public int RelayIndex
        {
            get { return _relayIndex; }
            set
            {
                _relayIndex = value;
                OnPropertyChanged("RelayIndex");
            }
        }
        /// <summary>
        /// 继电器对应的开关，有四个开关 1  2 3 4
        /// </summary>
        public int RelaySwitchIndex
        {
            get { return _relaySwitchIndex; }
            set
            {
                _relaySwitchIndex = value;
                OnPropertyChanged("RelaySwitchIndex");
            }
        }
        public bool DeleteFlag { get; set; }
        private ObservableCollection<ComboxSourceModel> _comboxSourceModelList;
        public ObservableCollection<ComboxSourceModel> ComboxSourceModelList
        {
            get
            {
                _comboxSourceModelList = new ObservableCollection<ComboxSourceModel>();
                _comboxSourceModelList.Add(
                    new ComboxSourceModel()
                    {
                        Key = 0,
                        Value = "八路控制器",
                        Type = "ControllerType",
                    });
                _comboxSourceModelList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 1,
                     Value = "十六路控制器",
                     Type = "ControllerType",
                 });
                _comboxSourceModelList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 2,
                     Value = "四路控制器",
                     Type = "ControllerType",
                 });

                return _comboxSourceModelList;
            }
        }
        private ObservableCollection<ComboxSourceModel> _comboxFactoryList;
        public ObservableCollection<ComboxSourceModel> ComboxFactoryList
        {
            get
            {
                _comboxFactoryList = new ObservableCollection<ComboxSourceModel>();
                _comboxFactoryList.Add(
                    new ComboxSourceModel()
                    {
                        Key = 0,
                        Value = "化能汇通",
                        Type = "ControllerFactory",
                    });
                _comboxFactoryList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 1,
                     Value = "鑫豪斯电子",
                     Type = "ControllerFactory",
                 });
                _comboxFactoryList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 2,
                     Value = "FMC_1000PLUS",
                     Type = "ControllerFactory",
                 });
                _comboxFactoryList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 3,
                     Value = "深圳特安",
                     Type = "ControllerFactory",
                 });
                _comboxFactoryList.Add(
                 new ComboxSourceModel()
                 {
                     Key = 4,
                     Value = "4~20mA转485",
                     Type = "ControllerFactory",
                 });
                _comboxFactoryList.Add(
                new ComboxSourceModel()
                {
                    Key = 5,
                    Value = "ES2000",
                    Type = "ControllerFactory",
                });
                _comboxFactoryList.Add(
                new ComboxSourceModel()
                {
                    Key = 6,
                    Value = "SP_1003Plus",
                    Type = "ControllerFactory",
                });
                _comboxFactoryList.Add(
                new ComboxSourceModel()
                {
                    Key = 7,
                    Value = "河南驰诚QB系列",
                    Type = "ControllerFactory",
                });
                _comboxFactoryList.Add(
               new ComboxSourceModel()
               {
                   Key = 8,
                   Value = "无锡科士特GM系列",
                   Type = "ControllerFactory",
               });
                _comboxFactoryList.Add(
            new ComboxSourceModel()
            {
                Key = 9,
                Value = "ES2000_D系列",
                Type = "ControllerFactory",
            });

                _comboxFactoryList.Add(
       new ComboxSourceModel()
       {
           Key = 10,
           Value = "TON9B0",
           Type = "ControllerFactory",
       });
                _comboxFactoryList.Add(
   new ComboxSourceModel()
   {
       Key = 10,
       Value = "DMC6000",
       Type = "ControllerFactory",
   });
                //霍尼韦尔
                //深圳特安
                //4~20mA转485
                return _comboxFactoryList;
            }
        }
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}
